{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Context Menu Action"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mapList = [\n",
    "   [a:1, b:2, c:3],\n",
    "   [a:4, b:5, c:6],\n",
    "   [a:7, b:8, c:5]\n",
    "]\n",
    "display1 = new TableDisplay(mapList)\n",
    "display1.addContextMenuItem(\"plusOne\") { row, col, tableDisplay ->\n",
    "   tableDisplay.values[row][col]++;\n",
    "}\n",
    "display1.addContextMenuItem(\"tag1ByStr\", \"tag1\");\n",
    "display1.addContextMenuItem(\"tag1ByClosure\") { row, col, tableDisplay ->\n",
    "   beakerx.runByTag(\"tag1\"); \n",
    "}\n",
    "display1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag1"
    ]
   },
   "outputs": [],
   "source": [
    "details = display1.details\n",
    "print(details.row + \":\" + details.col + \"=\" + display1.values[details.row][details.col])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// cell1 expected result\n",
    "Image(\"../../resources/img/groovy/tableActions/cell1_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// cell1 expected result after menu action\n",
    "Image(\"../../resources/img/groovy/tableActions/cell1_case2.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DoubleClick Action"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mapList = [\n",
    "   [a:1, b:2, c:3],\n",
    "   [a:4, b:5, c:6],\n",
    "   [a:7, b:8, c:5]\n",
    "]\n",
    "display2 = new TableDisplay(mapList)\n",
    "display2.setDoubleClickAction { row, col, tableDisplay ->\n",
    "   tableDisplay.values[row][col]++;\n",
    "}\n",
    "display2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// cell2 expected result\n",
    "Image(\"../../resources/img/groovy/tableActions/cell2_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// cell2 expected result after doubleClick action\n",
    "Image(\"../../resources/img/groovy/tableActions/cell2_case2.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run tag by string parameter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display3 = new TableDisplay(mapList)\n",
    "display3.setDoubleClickAction(\"tag3\")\n",
    "display3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag3"
    ]
   },
   "outputs": [],
   "source": [
    "details = display3.details\n",
    "print(details.row + \":\" + details.col + \"=\" + display3.values[details.row][details.col])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// cell3 expected result\n",
    "Image(\"../../resources/img/groovy/tableActions/cell3_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run tag by closure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display4 = new TableDisplay(mapList)\n",
    "display4.setDoubleClickAction{ row, col, tableDisplay ->\n",
    "   beakerx.runByTag(\"tag4\");\n",
    "}\n",
    "display4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "tag4"
    ]
   },
   "outputs": [],
   "source": [
    "details = display4.details\n",
    "print(details.row + \":\" + details.col + \"=\" + display4.values[details.row][details.col])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// cell4 expected result\n",
    "Image(\"../../resources/img/groovy/tableActions/cell4_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Groovy",
   "language": "groovy",
   "name": "groovy"
  },
  "language_info": {
   "codemirror_mode": "groovy",
   "file_extension": ".groovy",
   "mimetype": "",
   "name": "Groovy",
   "nbconverter_exporter": "",
   "version": "2.4.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": false,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": false,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
